package com.Dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import util.DBHelp;
import util.RowMapper;



import com.entity.Task;

public class TaskDao {

	private DBHelp<Task> db = new DBHelp<Task>();

	public List<Task> goalid(int goalid) {
		String sql = "SELECT * FROM t_task WHERE goalid = ?";
		return db.queryForList(sql, new Mr(), goalid );
	}
	
	class Mr implements RowMapper<Task>{
		public Task mapperRow(ResultSet rs) throws SQLException {
			Task tk=new Task();
			tk.setId(rs.getInt("id"));
			tk.setName(rs.getString("name"));
			tk.setDesc(rs.getString("desc"));
			tk.setState(rs.getString("state"));
			tk.setLevel(rs.getString("level"));
			tk.setBegintime(rs.getString("begintime"));
			tk.setEndtime(rs.getString("endtime"));
			tk.setCreatetime(rs.getString("createtime"));
			tk.setGoalid(rs.getInt("goalid"));
			tk.setRale(rs.getInt("rale"));
			return tk;
		}
	
	}

	public void update(Task tk) {
			String sql="UPDATE t_task SET `name`= ?,`desc`= ?, `state` =? ,`level` = ?,`begintime`=?,`endtime`=?,`createtime`=?, `rale`=? WHERE id = ?";
			db.executeSQL(sql, tk.getName(),tk.getDesc(),tk.getState(),tk.getLevel(),tk.getBegintime(),tk.getEndtime(),tk.getCreatetime(),tk.getRale(),tk.getId());
		
	}

	public void save(Task tk) {
		String sql = "INSERT INTO t_task(`name`,`desc`,createtime,state`,level`,begintime,endtime,employeeid,goalid,rale)VALUES(?,?,?,?,?,?,?,?,?,?)";
		db.executeSQL(sql, tk.getName(), tk.getDesc(), tk.getCreatetime(),tk.getState(),tk.getLevel(),tk.getBegintime(),tk.getEndtime(),tk.getEmployeeid(),tk.getGoalid(),tk.getRale());
		
	}
}
